package cn.com.pxto.service.impl;

import java.util.HashMap;
import java.util.List;

import cn.com.pxto.commons.pagesupport.PageInfo;
import cn.com.pxto.dao.LessonDAO;
import cn.com.pxto.dao.LessonTypeDAO;
import cn.com.pxto.dao.SchoolDAO;
import cn.com.pxto.model.Lesson;
import cn.com.pxto.model.LessonType;
import cn.com.pxto.model.School;
import cn.com.pxto.service.SchoolManager;

public class SchoolManagerImpl implements SchoolManager {
	private LessonTypeDAO lessonTypeDAO;
	private LessonDAO lessonDAO;
	private SchoolDAO schoolDAO;

	@Override
	public void createLesson(Lesson lesson) {
		lessonDAO.saveLesson(lesson);

	}

	@Override
	public void createLessonType(LessonType lessonType) {
		lessonTypeDAO.saveLessonType(lessonType);

	}

	@Override
	public void createSchool(School school) {
		schoolDAO.saveSchool(school);

	}

	@Override
	public void deleteLesson(int id) {
		lessonDAO.deleteLesson(id);

	}

	@Override
	public void deleteLessonType(int id) {
		lessonTypeDAO.deleteLessonType(id);

	}

	@Override
	public void deleteSchool(int id) {
		schoolDAO.deleteSchool(id);

	}

	@Override
	public Lesson getLesson(int id) {
		return lessonDAO.getLesson(id);
	}

	@Override
	public Lesson getLessonByName(String name) {
		return lessonDAO.getLesson(name);
	}

	@Override
	public LessonType getLessonType(int id) {
		return lessonTypeDAO.getLessonType(id);
	}

	@Override
	public LessonType getLessonTypeByName(String name) {
		return lessonTypeDAO.getLessonType(name);
	}

	@Override
	public School getSchool(int id) {
		return schoolDAO.getSchool(id);
	}

	@Override
	public School getSchoolByName(String name) {
		return schoolDAO.getSchool(name);
	}

	@Override
	public List<Lesson> listALLLesson() {
		// TODO Auto-generated method stub
//		return lessonDAO.listLessonType(pageInfo);
		return lessonDAO.listLesson();
	}

	@Override
	public List<LessonType> listAllLessonType() {
		return lessonTypeDAO.listLessonType();
	}

	@Override
	public List<School> listAllSchool() {
		return schoolDAO.listSchool();
	}

	@Override
	public List<Lesson> listLesson(PageInfo pageInfo) {
		return lessonDAO.listLesson(pageInfo);
	}

	@Override
	public List<LessonType> listLessonType(PageInfo pageInfo) {
		return lessonTypeDAO.listLessonType(pageInfo);
	}

	@Override
	public List<School> listSchool(PageInfo pageInfo) {
		return schoolDAO.listSchool(pageInfo);
	}

	@Override
	public void updateLesson(Lesson lesson) {
		lessonDAO.updateLesson(lesson);

	}

	@Override
	public void updateLessonType(LessonType lessonType) {
		lessonTypeDAO.updateLessonType(lessonType);

	}

	@Override
	public void updateSchool(School school) {
		schoolDAO.updateSchool(school);

	}

	public void setLessonTypeDAO(LessonTypeDAO lessonTypeDAO) {
		this.lessonTypeDAO = lessonTypeDAO;
	}

	public void setLessonDAO(LessonDAO lessonDAO) {
		this.lessonDAO = lessonDAO;
	}

	public void setSchoolDAO(SchoolDAO schoolDAO) {
		this.schoolDAO = schoolDAO;
	}

	@SuppressWarnings("unchecked")
	@Override
	public HashMap getSchoolLessonType() {
		HashMap<String ,String> lessonTypeMap=new HashMap();
		List<School> schoolList=schoolDAO.listSchool();
		if (schoolList!=null && schoolList.size()>0) {
			for (int i = 0; i < schoolList.size(); i++) {
				String shoolLessonTypeStr=schoolList.get(i).getLessonTypeStr();
//				去掉最后的，
				String temp = shoolLessonTypeStr.substring(0, shoolLessonTypeStr.length()-1);
				temp = temp.substring(1, temp.length());
				String str=lessonTypeDAO.getLessonTypeByString(temp);
				lessonTypeMap.put(schoolList.get(i).getLessonTypeStr(), str);
			}
		}
		return lessonTypeMap;
	}

	@Override
	public List<School> getSchoolByLessonsType(String typeId) {
		return schoolDAO.getSchoolByClassType(typeId);
	}

}
